package org.apache.doris.demo.spring.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.doris.demo.spring.model.EvenData;
import org.apache.doris.demo.spring.model.UserTag;
import org.apache.doris.demo.spring.service.UserTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.*;

@Controller
public class ChartController {
    @Autowired
    private UserTagService userTagService;
    @GetMapping("/chart")
    public String showChart(Model model) {
        String[] timelineData = {"2021", "2022", "2023"};
        List<EvenData> eventData = new ArrayList<>();
        eventData.add(new EvenData("2021年售假被处罚", "2021"));
        eventData.add(new EvenData("2022年被刑拘", "2022"));
        eventData.add(new EvenData("2023年被处罚", "2023"));
        List<UserTag> userTags = userTagService.list(new QueryWrapper<UserTag>().eq("userid", 1003));
        ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Random random = new Random();
        for (UserTag userTag : userTags) {
            Map<String, Object> data = new HashMap<>();
            int value = random.nextInt(10000 - 1000 + 1) + 1000;
            data.put("name", userTag.getTagName());
            data.put("value", value);
            list.add(data);
        }
        model.addAttribute("timelineData", timelineData);
        model.addAttribute("eventData", eventData);
        model.addAttribute("data", list);
        return "chart";
    }
}